<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>医生登录</title>
    <script src="{{url_for('static', filename='js/jquery-3.6.0.min.js')}}"></script>
    <script src="{{url_for('static', filename='js/custom_message_box.js')}}"></script>
    <link rel="stylesheet" href="{{url_for('static', filename='css/custom_message_box.css')}}">
    <link href="{{url_for('static', filename='css/layui.css')}}" rel="stylesheet">
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            margin: 20px;
            padding: 0;
            background: url("{{url_for('static', filename='img/login_admin_web.jpg')}}") no-repeat center;
            background-size: cover;
        }

        h2 {
            margin-bottom: 20px;
        }

        form {
            max-width: 300px;
        }

        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            box-sizing: border-box;
            font-size: 16px;
        }

        input[type="submit"] {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            cursor: pointer;
            font-size: 16px;
        }

        input[type="submit"]:hover {
            background-color: #45a049;
        }

        label {
            margin-bottom: 5px;
            display: block;
        }

        #login_box {
            background-color: rgba(226, 234, 244, 0.5);
            height: 300px;
            width: 250px;
            margin: 250px auto;
            border-radius: 20px;
            padding: 50px;
        }
    </style>
    <script>

        document.getElementById("loginForm").addEventListener("submit", function (event) {
            event.preventDefault();

            const username = document.getElementById("username").value;
            const password = document.getElementById("password").value;

            fetch("{{url_for('doctor.login_doctor')}}", {
                method: "POST",
                headers: {
                    "Content-Type": "application/json"
                },
                body: JSON.stringify({ "username": username, "password": password })
            })
                .then(response => response.json())
                .then(data => {
                    if (data.code === 0) {
                        showMessage("success", "Login successful! Redirecting to dashboard...", "message", 1000);
                        setTimeout(
                            () => {
                                window.location.href = "{{url_for('doctor.dashboard_doctor_web')}}";
                            }, 1000
                        )
                    } else {
                        showMessage("error", "Login failed: " + data.message, "message", 3000);
                    }
                })
                .catch(error => {
                    console.error("Error:", error);
                    showMessage("error", "An error occurred while trying to log in.", "message", 3000);
                });
        });
    </script>
</head>

<body>
    <div id="message" class="message-box"></div>
    <div id="login_box">
        <h2 style="text-align: center">医生登录</h2>
        <form id="loginForm" action="{{url_for('doctor.login_doctor')}}" method="POST">
            <label for="username">用户名:</label>
            <input type="text" id="username" name="username" placeholder="用户名" required>
            <br>
            <label for="password">密码:</label>
            <input type="password" id="password" name="password" placeholder="密码" required>
            <br>
            <div style="text-align: center">
                <input type="submit" value="登录">
            </div>
        </form>
    </div>
</body>

</html>